package com.sinbad.interview.spring.controller;

import com.sinbad.interview.spring.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/sign")
public class SignController {

    @Autowired
    private SignService signService;

    @PostMapping("/{userId}")
    public String sign(@PathVariable Long userId) {
        boolean signed = signService.doSign(userId);
        return signed ? "签到成功" : "已经签到过了";
    }

    @GetMapping("/check/{userId}/{day}")
    public boolean checkSign(@PathVariable Long userId, @PathVariable int day) {
        return signService.checkSign(userId, day);
    }

    @GetMapping("/count/{userId}")
    public long countSign(@PathVariable Long userId) {
        return signService.countSignedDays(userId);
    }

    @GetMapping("/log/{userId}")
    public Map<Integer, Boolean> signLog(@PathVariable Long userId) {
        return signService.getSignLog(userId);
    }
}
